package com.bstek.uflo.console.view.security.filter.impl;

import java.util.List;

import org.springframework.stereotype.Component;

import com.bstek.dorado.view.ViewElement;
import com.bstek.dorado.view.widget.form.autoform.AutoForm;
import com.bstek.uflo.console.view.security.filter.AbstractElementFilter;
import com.bstek.uflo.process.security.Authority;
import com.bstek.uflo.process.security.ComponentAuthority;

/**
 * @author Jacky.gao
 * @since 2013年10月21日
 */
@Component("uflo.console.autoFormElementFilter")
public class AutoFormElementFilter extends AbstractElementFilter {

	public boolean support(ViewElement element) {
		return element instanceof AutoForm;
	}

	public void filter(ViewElement element,List<ComponentAuthority> componentAuthorities) {
		AutoForm form=(AutoForm)element;
		String id=form.getId();
		Authority auth=filterComponent(id,componentAuthorities);
		if(auth!=null){
			if(auth.equals(Authority.Read)){
				form.setReadOnly(true);
			}else if(auth.equals(Authority.Hide)){
				form.setIgnored(true);
			}
		}
	}
}
